package com.dqhl.community.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.dqhl.community.R;
import com.dqhl.community.base.BaseMyAdapter;
import com.dqhl.community.model.FamilyProjectBean;
import com.dqhl.community.util.ViewHolder;

import java.util.List;

/**
 * Created by Administrator on 2016/9/11.
 */
public class ApplianceCleanAdapter extends BaseMyAdapter {

    List<FamilyProjectBean> list;
    private int selectedPosition=0;
    public ApplianceCleanAdapter(Context context, List<FamilyProjectBean> list) {
        super(context);
        this.list=list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }
    public void clearSelection(int position) {
        selectedPosition = position;
    }
    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        if(view == null){
            view = inflater.inflate(R.layout.gv_clean_project_item, viewGroup, false);
        }
        ImageView iv_cleanProject = ViewHolder.get(view,R.id.iv_clean);
        TextView mTvTitle =  ViewHolder.get(view,R.id.tv_family_item_1);
        FamilyProjectBean familyProjectBean = list.get(i);
        mTvTitle.setText(familyProjectBean.getType());
        if("洗衣机".equals(familyProjectBean.getType())){
            iv_cleanProject.setImageResource(R.drawable.ic_washer);
        }else if("抽油烟机".equals(familyProjectBean.getType())){
            iv_cleanProject.setImageResource(R.drawable.ic_smoke);
        }else if("空调".equals(familyProjectBean.getType())){
            iv_cleanProject.setImageResource(R.drawable.ic_air);
        } else if("微波炉".equals(familyProjectBean.getType())){
            iv_cleanProject.setImageResource(R.drawable.ic_microwave);
        }else if("热水器".equals(familyProjectBean.getType())){
            iv_cleanProject.setImageResource(R.drawable.ic_water);
        }else if("冰箱".equals(familyProjectBean.getType())){
            iv_cleanProject.setImageResource(R.drawable.ic_freezer);
        }
        if(selectedPosition==i){
            mTvTitle.setTextColor(Color.parseColor("#ff6501"));
            view.setBackgroundResource(R.color.grayC7);
        }else{
            mTvTitle.setTextColor(Color.parseColor("#404040"));
            view.setBackgroundResource(R.color.white);
        }
        return view;
    }
}
